//
//  History.m
//  Maciago
//
//  Created by mmarcos on Thu Oct 04 2001.
//  Copyright (c) 2001 __CompanyName__. All rights reserved.
//

#import "History.h"

@interface History (ProtectedMethods)
-_init;
+alloc;
@end


@implementation History

+ alloc
{
    NSLog (@"Warning: Calling History alloc, use sharedInstance instead");
    return [self sharedInstance];
}

- _init
{
    array = [[NSMutableArray alloc] init];
    currentIndex = -1;

    return self;
}

+ sharedInstance
{
    static History *instance = nil;

    if (instance == nil)
    {
//	NSLog (@"Calling History sharedInstance (1st time)");
	instance = [[super alloc] _init];
    }
//    else
//	NSLog (@"Calling History sharedInstance (>1 time)");
    
    return instance;
}

- (void)dealloc
{
    [super dealloc];
}

- (id)currentItem
{
    if (currentIndex >= 0)
	return [array objectAtIndex:currentIndex];
    
    return nil;
}

- (void)addItem:(id)item
{
    [array addObject:item];
    ++currentIndex;
}

- (id)previousItem
{
    if (currentIndex > 0)
    {
	return [array objectAtIndex:currentIndex-1];
    }
    return nil;
}
- (id)nextItem
{
    if (currentIndex > ([array count] - 1))
    {
	return [array objectAtIndex:currentIndex+1];
    }
    return nil;
}

- (void)clearAll
{
    [array removeAllObjects];
    currentIndex = -1;
}

- (void)clearNextItems
{}

- (void)clearPreviousItems
{}

@end
